package com.market.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.market.entity.BuyerCashFlow;
import com.market.mapper.BuyerCashFlowMapper;
import com.market.service.BuyerCashFlowService;
import com.market.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @ClassName BuyerCashFlowController
 * @Description 买家资金流水
 * @Author pq
 * @Date 2022/3/29 19:19
 * @Version 1.0
 */
@RestController
@RequestMapping("buyerCashFlow")
public class BuyerCashFlowController {

    @Autowired
    BuyerCashFlowService buyerCashFlowService;
    @Autowired
    BuyerCashFlowMapper buyerCashFlowMapper;

    //增加买家流水
    @PostMapping("addBuyerCashFlow")
    public R addBuyerCashFlow(@RequestBody BuyerCashFlow buyerCashFlow){
        if(buyerCashFlowService.addBuyerCashFlow(buyerCashFlow)){
            return new R(200,"买家资金流水增加成功");
        }else{
            return new R(201,"买家资金流水增加失败");
        }
    }

    //查询所有流水
    @GetMapping("queryAllBuyerCashFlow")
    public R queryBuyerCashFlow(int buyerId, int currentPage, int pageSize){
        PageHelper.startPage(currentPage,pageSize);
        List<BuyerCashFlow> result=buyerCashFlowService.queryAllBuyerCashFlow(buyerId);
        if(result.size()!=0){
            return new R(200,"查询所有流水成功",new PageInfo<>(result));
        }else{
            return new R(201,"查询所有流水失败");
        }
    }

}
